package data;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;

import logic.Answer;
import logic.Course;
import logic.Degree;
import logic.Question;
import logic.Test;
import logic.University;

public class DATA_Helper {

	private static DB_Helper db;
	private static API_Helper api;
	private Context context;
	public static List<Test> tests;

	public static final String TESTS = "tests_list";

	public DATA_Helper(Context context) {
		this.context = context;
		db = new DB_Helper(context, null);
		api = new API_Helper();
	}

	public static List<Test> getOfflineTests() {
		db.close();
		tests = db.getTests(true, null);
		return tests;
	}

	public List<Test> getRecentTestsIds() {
		return db.getRecentTests();
	}

	public List<Question> getMistakenQuestions() {
		return null;
	}
	
	public static boolean deleteTestFromDB(Test test) {
		boolean success = db.deleteTest(test);
		db.close();
		return success;
	}
	
	public static void insertTest(Test test) {
		db.insertTest(test);
	}

	public static boolean insertUniversity(University u) {
		return db.insertUniversity(u);
	}

	public static List<University> getUniveristies() {
		return db.getUniversities();
	}

	public static List<Degree> getDegreesByUniversity(String uniId) {
		return api.getDegrees(uniId);
	}

	public static boolean insertDegree(Degree d) {
		return db.insertDegree(d);
	}

	public static List<Degree> getDegrees() {
		return db.getDegrees();
	}

	public static List<Course> getcoursesByDegree(String degreeId) {
		return api.getCourses(degreeId);
	}

	public static List<Test> getTestsByCourse(String courseId) {
		return api.getTests(courseId);
	}

	public static List<Question> getQuestionsByTest(String testId) {
		return api.getQuestions(testId);
	}

	public static List<Answer> getAnswersByQuestion(String idQuestion) {
		return api.getAnswers(idQuestion);
	}

	public static boolean existsTest(String testId) {
		return db.existsTest(testId);
	}

	public static boolean deleteDegreFromDB(Degree degree) {
		return db.deleteDegree(degree);
	}

	public static void insertTestAccess(String testId, String testName) {
		db.insertTestAccess(testId, testName);
	}

	public static List<Test> getTestSet(List<String> testsIds) {
//		return db.getTestsById(testsIds);
		List<Test> tests = new ArrayList<Test>();
		for (String s : testsIds) {
			tests.add(api.getTest(s));
		}
		return tests;
	}
}
